<template>
	<view class="introduction-container">
		<textarea type="text"  placeholder="开始介绍自己吧!" class="introduction-textarea" maxlength="-1" v-model="introduction" @input="onTextChange"/>
		<text class="tip">{{tetxLength}}/{{maxText}}</text>
	</view>
	<view class="introduction-btns-con">
		<button type="primary" class="introduction-btn" style="background: transparent; border: 1rpx solid #00b588; color: #00b588" @click="cancelIntroduction">取消</button>
		<button type="primary" class="introduction-btn" style="border: 20rpx; background: linear-gradient(90deg, #01e9bd 0%, #007cde 100%); color: #ffffff" @click="submitIntroduction">提交</button>
		
	</view>
</template>

<script setup>
import { onLoad } from "@dcloudio/uni-app";
import {updateUserBaselnfo} from "@/api/user/index.js";
import { ref,getCurrentInstance } from 'vue'

const {proxy} = getCurrentInstance();
const introduction = ref('');
const nickname = ref('')
const tetxLength = ref(0)
const maxText = ref(400)

onLoad((option)=>{
	console.log(option);
	
	introduction.value = option.introduction === "undefined" || option.introduction === "null"? "":option.introduction
	nickname.value = option.nickname
})
const submitIntroduction = async() =>{
	if(tetxLength.value>=maxText.value){
		proxy.modal.msg(`最多容纳${maxText.value}字`)
		return
	}
	let res = await updateUserBaselnfo({introductory:introduction.value})
	if(res.code==200){
		introduction.value = ''
		uni.showToast({
		  title: '修改成功',
		  icon: 'success',
		  duration: 2000
		})
		uni.navigateBack()
	};
}
const cancelIntroduction = ()=>{
	introduction.value = ''
	uni.navigateBack()
}

function onTextChange(e){
	tetxLength.value = introduction.value.length
	if(tetxLength.value>=maxText.value){
		proxy.modal.msg(`最多容纳${maxText.value}字`)
	}
}
</script>

<style lang="less" scoped>
	.introduction-container{
		width: 100%;
		margin-top: 20rpx;
		.tip{
			position: absolute;
			right: 30rpx;
			margin-top: 20rpx;
		}
	}
	.introduction-btns-con {
		position: fixed;
		bottom: 0;
		background-color: @color-font;
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 120rpx;
		width: 100%;
		.introduction-btn {
			width: 40%;
			border-radius: 50rpx;
			font-size: @font-size-31;
		}
	}
	.introduction-textarea{
		font-size: 31rpx;
		width: calc(100% - 100rpx);
		margin: 0 30rpx;
		height: 520rpx;
		background-color: #e3e3e375;
		padding: 20rpx;
		border-radius: 20rpx;
	}
</style>